package com.framework.loippi.controller.api;

import com.framework.loippi.api.utils.ApiUtils;
import com.framework.loippi.entity.TCart;
import com.framework.loippi.service.TCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName CartController
 * @Description TODO
 * @Author fsociety
 * @Date 28/12/2019 下午3:46
 * @Version 1.0
 */

@Controller("apiCartController")
@RequestMapping("/api/cart")
@Api(tags = {"购物车信息"})
public class CartController extends ApiBaseController {

   @Autowired
   TCartService cartService;

    @RequestMapping(value = "/add.json", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "添加购物车", notes = "{}")
    public @ResponseBody
    String addCart(TCart cart) {
        Long result = cartService.save(cart);

        return ApiUtils.success();
    }

    @RequestMapping(value = "/modify.json", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "修改购物车", notes = "{}")
    public @ResponseBody
    String modify(TCart cart) {
        Long result = cartService.update(cart);

        return ApiUtils.success();
    }

    @RequestMapping(value = "/delete.json", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "删除购物车", notes = "{}")
    public @ResponseBody
    String modify(Long cartId) {
        Long result = cartService.delete(cartId);

        return ApiUtils.success();
    }

    @RequestMapping(value = "/findByUserId.json", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "查询购物车", notes = "{}")
    public @ResponseBody
    String findByUserId(Integer userId) {
        List<TCart> list = cartService.findByUserId(userId);

        return ApiUtils.success(list);
    }


}
